<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>发布信息</title>

	<meta name="viewport" content="width=device-width"/>
	<meta name="viewport" content="initial-scale=1.0,user-scalable=no"/>
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name = "format-detection" content = "telephone=no">

	<link type="text/css" href="http://libkindle.com:8080/qd2/css/css.css" rel="stylesheet" />

	<script src="js/jquery.min.js"></script>
	<script src="js/app.js"></script>
	<script src="js/jquery.min.js"></script>
 <script type="text/javascript">  
	//iOS Web APP中点击链接跳转到Safari 浏览器新标签页的问题 devework.com  
	//stanislav.it/how-to-prevent-ios-standalone-mode-web-apps-from-opening-links-in-safari  
	if(("standalone" in window.navigator) && window.navigator.standalone){  
		var noddy, remotes = false;  
		document.addEventListener('click', function(event) {  
			noddy = event.target;
			while(noddy.nodeName !== "A" && noddy.nodeName !== "HTML") {  
				noddy = noddy.parentNode;  
			}  
			if('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes))  
			{  
				event.preventDefault();  
				document.location.href = noddy.href;  
			}  
		},false);  
	}  
  </script> 
	
</head>
<body>

<!--网页头部栏-->
	<div class="header">
	<table width="100%" border="0" cellspacing="0" class="header_nav">
		<tr>
			<td width="10%" class="nav_left1"><a  href='javascript:window.history.go(-1)'><</a></td>
			<td width="80%" class="nav_title">发布二手</td>
			<td width="10%" class="nav_r"></td>
		</tr>
	</table>
	</div>
	

<!--主体-->


	<div class="login">
		<div class="logo"></div>
		<div class="main">
			<CENTER>
				<div id="dd">
					<form enctype="multipart/form-data" id="upform">
						<a href="javascript:void(0);" class="file" cellspacing="0">
							+
							<input type="file" class="imgfile" name="imgurl" id="inputs" onchange="a()"></input>
						</a>
					</form>
				</div>
			</CENTER>
<!--
			<table width="100%" border="0" cellspacing="0" class="main1">
				<tr>
					<td class="text"><input type="text/css" class="text1" id="fabuname" placeholder="请输入您的姓名"/></td>
				</tr>
			</table>
			<div class="linee"></div>
			<table width="100%" border="0" cellspacing="0" class="main1">
				<tr>
					<td class="text"><input type="text/css" class="text1" id="fabuphone" placeholder="请输入您的电话号码"/></td>
				</tr>
			</table>
			<div class="linee"></div>
			<table width="100%" border="0" cellspacing="0" class="main1">
				<tr>
					<td class="text"><input type="text/css" class="text1" id="fabuqq" placeholder="请输入您的QQ号"/></td>
				</tr>
			</table>
			<div class="linee"></div>
			<table width="100%" border="0" cellspacing="0" class="main1">
				<tr>
					<td class="text"><input type="text/css" class="text1" id="fabulocation" placeholder="请输入您的位置"/></td>
				</tr>
			</table>
-->
			<table width="100%" border="0" cellspacing="0" class="main1">
				<tr>
					<td class="text"><input type="text/css" class="text1" id="prodname" placeholder="请输入产品名"/></td>
				</tr>
			</table>
			<div class="linee"></div>
			<table width="100%" border="0" cellspacing="0" class="main1">
				<tr>
					<td class="text"><input type="text/css" class="text1" id="stoke" placeholder="请输入产品库存"/></td>
				</tr>
			</table>
			<div class="linee"></div>
			<table width="100%" border="0" cellspacing="0" class="main1">
				<tr>
					<td class="text"><input type="text/css" class="text1" id="price" placeholder="请输入产品价格"/></td>
				</tr>
			</table>
			<div class="linee"></div>
			<table width="100%" border="0" cellspacing="0" class="main1">
				<tr>
					<td class="text"><input type="text/css" class="text1" id="description" placeholder="请输入产品描述"/></td>
				</tr>
			</table>
			<div class="linee"></div>
		<div>
		<br>
		<br>
		<button type="button" class="text2" onclick="javascript:tianjia()">发布</button>
		<br>
		<br>
		<br><br><br>
		</div>
			<!--需要与后台数据进行交互，将注册信息存入数据库中-->   
			<!--制作弹窗，或者一个倒计时返回页面，href=login.html-->
	</div>



<!--网页底部栏-->
<div>
	<table width="100%" border="0" cellspacing="0" class="nav">
		<tr>
			<td width="25" class="foot"><a href="index.html"><img src="img/function.png" width="20%" height="auto"/><p>分类</p></a></td>
			<td width="25" class="foot"><a href="addgoods.html"><img src="img/addgoods.png" width="20%" height="auto"/><p>发布</p></a></td> 
			<td width="25" class="foot"><a href="shopcard.html"><img src="img/shopcard.png" width="20%" height="auto"/><p>购物车</p></a></td>
			<td width="25" class="foot"><a href="member.html"><img src="img/myself.png" width="20%" height="auto"/><p>我的</p></a></td>
		</tr>
	</table>
</div>

<script type="text/javascript">
	var imgurl;
	var rootdir="http://libkindle.com:8080/WebSell/";
	function a(){
		var formData=new FormData($('form')[0]);
		//formData.append('file',$(':file')[0].files[0]);
		$.ajax({
			url: rootdir+"PictureServlet",
			type: 'POST',
			data: formData,
			contentType: false,
			processData:false,
			dataType: 'json',
			success: function(data,status,xhr) { 
				if(data.code==0){
					imgurl=data.iconurl;
					$("#dd").empty();
					$("#dd").append("<img src='"+rootdir+imgurl+"''>");
					console.log(rootdir+imgurl);
				}
				else{
					alert(data.msg);
				}
			},
			error: function(data,XMLHttpRequest,textStatus,errorThrown){
				alert("上传意外出错");
				console.log(data);
				console.log(XMLHttpRequest.status);
				console.log(XMLHttpRequest.readyState);
				console.log(textStatus);
			},
		});
	};
	function tianjia(){
		$.ajax({
			url: rootdir+"ProductServlet",
			type: 'GET',
			dataType: 'json',
			data: {
				action:"upload",
				prodname:$("#prodname").val(),
				stoke:$("#stoke").val(),
				price:$("#price").val(),
				icon:rootdir+imgurl,
				description:$("#description").val()
			},
			success: function(data,status,xhr) { 
				if(data.code==0){
					alert(data.msg);
					location.href = "index.html";
				}
				else{
					alert(data.msg);
				}
			},
			error: function() {
				alert("发送意外出错");
				console.log(data);
				console.log(XMLHttpRequest.status);
				console.log(XMLHttpRequest.readyState);
				console.log(textStatus);
			},
		});
	};
</script>

</body>
</html>